home *** CD-ROM | disk | FTP | other *** search
- //
- // File: MacFramework.h
- //
- // Contains: Basic functions for windows, menus, and similar things.
- //
- // Written by: Tim Monroe
- // Based on the MovieShell code written by Apple DTS.
- //
- // Copyright: © 1994-1998 by Apple Computer, Inc., all rights reserved.
- //
- // Change History (most recent first):
- //
- // <6> 11/02/98 rtm minor reworking to coordinate with WinFramework.h
- // <5> 11/07/97 rtm revised syntax of DoApplicationEventLoopAction
- // <4> 02/26/97 rtm added fCanEditMovie field to WindowObjectRecord
- // <3> 12/05/96 rtm added fMovie and fInstance to WindowObjectRecord
- // <2> 11/27/96 rtm conversion to personal coding style
- // <1> 12/20/94 khs first file
- //
-
- #pragma once
-
- // header files
-
- #ifndef __APPLEEVENTS__
- #include <AppleEvents.h>
- #endif
-
- #ifndef __DEVICES__
- #include <Devices.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __DISKINIT__
- #include <DiskInit.h>
- #endif
-
- #ifndef __FIXMATH__
- #include <FixMath.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __MACMEMORY__
- #include <MacMemory.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __MOVIES__
- #include <Movies.h>
- #endif
-
- #ifndef __PROCESSES__
- #include <Processes.h>
- #endif
-
- #ifndef __QUICKTIMECOMPONENTS__
- #include <QuickTimeComponents.h>
- #endif
-
- #ifndef __QUICKTIMEVR__
- #include <QuickTimeVR.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __SEGLOAD__
- #include <SegLoad.h>
- #endif
-
- #ifndef __SOUND__
- #include <Sound.h>
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __TRAPS__
- #include <Traps.h>
- #endif
-
- #ifndef __QTUtilities__
- #include "QTUtilities.h"
- #endif
-
- #include <stdio.h>
- #include <string.h>
-
-
- //////////
- //
- // constants
- //
- //////////
-
- #define kEmergencyMemorySize 40*1024L // size of the block of memory used for our grow zone procedure
- #define kExtraStackSpaceSize 32*1024L // amount of additional stack space
-
- #define kBroughtToFront 3 // number of times to call EventAvail at application startup
-
- #define kNewMovieName "untitled.mov" // default name of a movie created by "New" menu command
-
- #define kInvalidFileRefNum -1 // an invalid file reference number
-
- enum {
- kMovieControllerObject = FOUR_CHAR_CODE('MCvr')
- };
-
- // for menus
- enum eMenubar {
- mMenubar = 128
- };
-
- enum eMainMenus {
- mApple = 128,
- mFile,
- mEdit
- };
-
- enum eAppleMenu {
- iAbout = 1
- };
-
- enum eFileMenu {
- iNew = 1,
- iOpen,
- iClose,
- iSave,
- iSaveAs,
- iPrint = 7,
- iQuit = 9
- };
-
- enum eEditMenu {
- iUndo = 1,
- iCut = 3,
- iCopy,
- iPaste,
- iClear,
- iSelectAll = 8,
- iPreferences = 10
- };
-
- // for dialogs
- enum eDialogs {
- kAboutBoxID = 128, // dialog ID for About box
- kAlertErrorID = 129, // dialog ID for warning box
- kSaveDialogID = 130 // dialog ID for "Save changes..." dialog box
- };
-
- // items in these dialogs
- #define kSaveChanges 1 // save the changes before closing window
- #define kCancelClose 2 // no, don't close the window or save changes
- #define kDontSaveChanges 3 // discard any unsaved changes
-
-
- #define kOKButtonUserItem 4
-
- // constants for standard modal dialog filter proc
- #define kMyButtonDelay 8
- #define kReturnKey (char)0x0D
- #define kEnterKey (char)0x03
- #define kEscapeKey (char)0x1B
- #define kPeriod '.'
-
- // constants for selecting InitApplication phase
- enum {
- kInitAppPhase_BeforeCreateFrameWindow = 1L << 0, // MDI frame window windows not yet created
- kInitAppPhase_AfterCreateFrameWindow = 1L << 1, // MDI frame window windows already created
- kInitAppPhase_BothPhases = kInitAppPhase_BeforeCreateFrameWindow | kInitAppPhase_AfterCreateFrameWindow
- };
-
- // constants for selecting StopApplication phase
- enum {
- kStopAppPhase_BeforeDestroyWindows = 1L << 0, // movie windows not yet torn down
- kStopAppPhase_AfterDestroyWindows = 1L << 1, // movie windows already torn down
- kStopAppPhase_BothPhases = kStopAppPhase_BeforeDestroyWindows | kStopAppPhase_AfterDestroyWindows
- };
-
- // parameters to the SetMenuItemState function
- #define kEnableMenuItem 0x00000000L
- #define kDisableMenuItem 0x00000001L
-
- // resource ID for string resource containing application's name
- #define kAppNameResID 1000
- #define kAppNameResIndex 1
-
- #define kDefaultWindowTitle "\puntitled"
-
-
- /////////
- //
- // macros
- //
- //////////
-
- // macros for converting Mac menu ID/menu item pairs into a single "menu item identifier"
- #define MENU_IDENTIFIER(menuID,menuItem) ((menuID<<8)+(menuItem))
- #define MENU_ID(menuIdentifier) ((menuIdentifier&0xff00)>>8)
- #define MENU_ITEM(menuIdentifier) ((menuIdentifier&0x00ff))
-
-
- //////////
- //
- // data types
- //
- //////////
-
- typedef MenuHandle MenuReference;
- typedef WindowRef WindowReference;
- typedef short WORD;
-
-
- //////////
- //
- // structures
- //
- //////////
-
- // WindowObjectRecord is a data structure attached to a movie window.
- // We use this structure to associate data with any window presented.
-
- typedef struct {
- WindowReference fWindow; // the window
- OSType fObjectType; // specific tag indicating that the window object belongs to our application
- Movie fMovie; // the main movie (QT or QTVR)
- MovieController fController; // the movie controller for this window
- FSSpec fFileFSSpec; // location of the movie file
- short fFileResID;
- short fFileRefNum;
- Boolean fCanResizeWindow; // can the window be resized?
- Boolean fDirty; // has the movie data changed since the last save?
- QTVRInstance fInstance; // the QTVRInstance
- Handle fAppData; // a handle to application-specific window data
- } WindowObjectRecord, *WindowObjectPtr, **WindowObject;
-
-
- //////////
- //
- // function prototypes
- //
- //////////
-
- void InitStack (long extraStackSpace);
- void InitMacEnvironment (long nMoreMasters);
- pascal long AppGrowZoneCallback (Size theBytesNeeded);
- Boolean InitMenubar (void);
- void MainEventLoop (void);
- void HandleMenuCommand (long theMenuResult);
- void AdjustMenus (void);
- void HandleKeyPress (EventRecord *theEvent);
- void QuitFramework (void);
-
- Boolean DoCreateNewMovie (void);
- MovieController SetupMovieWindowWithController (Movie theMovie, WindowReference theWindow, Boolean theMoveWindow);
- Boolean DoCreateMovieWindow (Movie theMovie, FSSpec *theFSSpec);
- void DoDestroyMovieWindow (WindowReference theWindow);
- OSErr DoSaveAsMovieFile (WindowReference theWindow);
- Boolean DoUpdateMovieFile (WindowReference theWindow);
- void DoActivateWindow (WindowReference theWindow, Boolean becomingActive);
- PASCAL_RTN void StandardUserItemProcedure (DialogPtr theDialog, short theItem);
- PASCAL_RTN Boolean StandardModalDialogEventFilter (DialogPtr theDialog, EventRecord *theEvent, short *theItemHit);
- Boolean CheckMovieControllers (EventRecord *theEvent);
-
- Boolean IsAppWindow (WindowReference theWindow);
- Boolean IsDocWindow (WindowReference theWindow);
- WindowObject CreateWindowObject (WindowReference theWindow);
-
- void SizeWindowToMovie (WindowObject theWindowObject);
- void ShowAboutBox (void);
- void ShowWarning (Str255 theMessage, OSErr theErr);
-
- WindowReference GetFrontMovieWindow (void);
- WindowReference GetNextMovieWindow (WindowReference theWindow);
- WindowObject GetWindowObjectFromFrontWindow (void);
- WindowObject GetWindowObjectFromWindow (WindowReference theWindow);
- MovieController GetMCFromFrontWindow (void);
- MovieController GetMCFromWindow (WindowReference theWindow);
- QTVRInstance GetQTVRInstanceFromFrontWindow (void);
- Handle GetAppDataFromFrontWindow (void);
- Handle GetAppDataFromWindow (WindowReference theWindow);
- Handle GetAppDataFromWindowObject (WindowObject theWindowObject);
- Boolean IsWindowObjectOurs (WindowObject theObject);
- void DoBeep (void);
- void SetMenuState (MenuReference theMenu, UInt16 theMenuItem, short theState);
- void SetMenuItemState (MenuReference theMenu, UInt16 theMenuItem, short theState);
- void SetMenuItemLabel (MenuReference theMenu, UInt16 theMenuItem, char *theText);
- void SetMenuItemCheck (MenuReference theMenu, UInt16 theMenuItem, Boolean theState);
- GrafPtr GetPortFromWindowReference (WindowReference theWindow);
- WindowReference GetWindowReferenceFromPort (GrafPtr thePort);
- short GetWindowWidth (WindowReference theWindow);
- WindowReference GetFrontAppWindow (void);
- WindowReference GetNextAppWindow (WindowReference theWindow);
-
-
- // application-specific functions
- // These are defined in the ComApplication.c file;
- // you could override these to change the behavior of the function in a specific application.
- void InitApplication (UInt32 theStartPhase);
- void StopApplication (UInt32 theStopPhase);
- void DoIdle (WindowReference theWindow);
- void DoUpdateWindow (WindowReference theWindow, Rect *theRefrehArea);
- void HandleContentClick (WindowReference theWindow, EventRecord *theEvent);
- Boolean HandleApplicationKeyPress (char theCharCode);
- WindowRef CreateMovieWindow (Rect *theRect, Str255 theTitle);
- void HandleApplicationMenu (UInt16 theMenuItem);
- void AdjustApplicationMenus (WindowReference theWindow, MenuReference theMenu);
- Boolean DoApplicationEventLoopAction (EventRecord *theEvent);
- void AddControllerFunctionality (MovieController theMC);
- void InitApplicationWindowObject (WindowObject theWindowObject);
- void RemoveApplicationWindowObject (WindowObject theWindowObject);
- PASCAL_RTN Boolean ApplicationMCActionFilterProc (MovieController theMC, short theAction, void *theParams, long theRefCon);
-